<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>管理员信息管理</title>
<script type="text/javascript">
	var urL;
	
	function delAdmin(){
		//获得选中数据对象
		var selectedRows=$("#dg").datagrid('getSelections');
		if(selectedRows.length==0){
			$.messager.alert("系统提示","请选择要删除的数据！");
			return;
		}
		var strIds=[];//要删除的序号组合
		for(var i=0;i<selectedRows.length;i++){
			strIds.push(selectedRows[i].adminid);
		}
		var ids=strIds.join(",");
		$.messager.confirm("系统提示","您确认要删掉这<font color=red>"+selectedRows.length+"</font>条数据吗？",function(r){
			if(r){
				//ajax提交 delIds
				$.post("delAdmin",{adminids:ids},function(result){
					if(result){
						$.messager.alert("系统提示","您已成功删除<font color=red>"+selectedRows.length+"</font>条数据！");
						$("#dg").datagrid("reload");
					}else{
						$.messager.alert('系统提示',"删除失败");
					}
				},"json");
			}
		});
	}
	
	//查询符合条件的用户
	function searchAdmin(){
		$('#dg').datagrid('load',{
			adminid:$('#adminid').val(),
			adminname:$('#adminname').val(),
			adminphone:$('#adminphone').val(),
		});
	}
	
	function openAdminAddDialog(){
		reset();
		$("#dlg").dialog("open").dialog("setTitle","添加管理员信息");
		$("#madminid").attr("readonly",false);
		urL = "addAdmin";
	}
	
	function openAdminModifyDialog(){
		var selectedRows=$("#dg").datagrid('getSelections');
		if(selectedRows.length!=1){
			$.messager.alert("系统提示","请选择一条要编辑的数据！");
			return;
		}
		var row=selectedRows[0];
		$("#dlg").dialog("open").dialog("setTitle","编辑管理员资料");
		$("#madminid").val(row.adminid);
		$("#madminname").val(row.adminname);
		$('#madminphone').val(row.adminphone);
		$('#madminpwd').val(row.adminpwd);
		urL = "updateAdmin";
	}
	
	function saveAdmin(){
		$("#fm").form("submit",{
			url:urL,
			onSubmit:function(){
				if($('#madminname').val()==""){
					$.messager.alert("系统提示","请输入管理员姓名");
					return false;
				}
				if($('#madminphone').val()==""){
					$.messager.alert("系统提示","请输入管理员联系方式");
					return false;
				}
				return $(this).form("validate");
			},
			success:function(result){
				if(result){
					$.messager.alert("系统提示","保存成功");
					$("#dlg").dialog("close");
					$("#dg").datagrid("reload");
				}else{
					$.messager.alert("系统提示","保存失败");
					return;
				}
			}
		});
	}
	
	function reset(){
		
		$("#madminid").val("");
		$("#madminname").val("");
		$('#madminphone').val("");
		$('#madminpwd').val("");
	}
	//关闭对话框
	function closeAdminDialog(){
		$("#dlg").dialog("close");
	}
</script>
<link rel="stylesheet" type="text/css"  href="../easyui-1.5/themes/default/easyui.css" />
<link rel="stylesheet" type="text/css"  href="../easyui-1.5/themes/icon.css" />
<script type="text/javascript" src="../easyui-1.5/jquery.min.js"></script>
<script type="text/javascript" src="../easyui-1.5/jquery.easyui.min.js"></script>
<script type="text/javascript" src="../easyui-1.5/locale/easyui-lang-zh_CN.js"></script>
</head>
<body style="margin:5px">
	<table id="dg" title="管理员信息" class="easyui-datagrid" fitColumns="true" striped="true"
	 pagination="true" rownumbers="true" url="getAdminList" fit="true" toolbar="#tb" datapagesize="5">
		<thead>
			<tr>
				<th field="cb" checkbox="true"></th>
				<th field="adminid" width="100" align="center">用户id</th>
				<th field="adminname" width="100" align="center">用户名</th>
				<th field="adminphone" width="100" align="center">联系方式</th>
				<th field="adminpwd" width="100" align="center" hidden="true">密码</th>
				
			</tr>
		</thead>
	</table>
	<div id="tb">
		<div>
			<a href="javascript:openAdminAddDialog()" class="easyui-linkbutton" iconCls="icon-add" plain="true">添加</a>
			<a href="javascript:openAdminModifyDialog()" class="easyui-linkbutton" iconCls="icon-edit" plain="true">修改</a>
			<a href="javascript:delAdmin()" class="easyui-linkbutton" iconCls="icon-remove" plain="true">删除</a>
		</div>
		<div>
			<form id="export" method="post">
			&nbsp;用户名：&nbsp;<input type="text" name="adminid" id="adminid" size="10"/>
			&nbsp;姓名：&nbsp;<input type="text" name="adminname" id="adminname" size="10"/>
			&nbsp;联系方式：&nbsp;<input type="text" name="adminphone" id="adminphone" size="10"/>
			<a href="javascript:searchAdmin()" class="easyui-linkbutton" iconCls="icon-search" plain="true">搜索</a>
			</form>
		</div>
	</div>
	<div id="dlg" class="easyui-dialog" style="width: 550px;height: 240px;padding: 10px 20px"
		closed="true" buttons="#dlg-buttons">
		<form id="fm" method="post">
			<table cellspacing="5px;">
				<tr>		
					<td>管理员id：</td>
					<td><input type="text" name="adminid" id="madminid" class="easyui-validatebox" required="true" readonly/></td>
					<td>姓名：</td>
					<td><input type="text" name="adminname" id="madminname" class="easyui-validatebox" required="true"/></td>
				</tr>
				<tr>
					<td>联系方式：</td>
					<td><input type="text" name="adminphone" id="madminphone" class="easyui-validatebox" data-options="required:true,validType:'length[11,11]'"/></td>
					<td>密码：</td>
					<td><input type="text" name="adminpwd" id="madminpwd" class="easyui-validatebox" required="true"/></td>
				</tr>
			</table>
		</form>
	</div>
	
	<div id="dlg-buttons">
		<a href="javascript:saveAdmin()" class="easyui-linkbutton" iconCls="icon-ok">保存</a>
		<a href="javascript:closeAdminDialog()" class="easyui-linkbutton" iconCls="icon-cancel">关闭</a>
	</div>
	
</body>
</html>